﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package zasp.Util {
    import flash.utils.*;

    public class BloomFilter {

        public static var RS:int = 0;
        public static var JS:int = 1;
        public static var PJW:int = 2;
        public static var ELF:int = 3;
        public static var BKDR:int = 4;
        public static var SDBM:int = 5;
        public static var DJB:int = 6;
        public static var DEK:int = 7;
        public static var BP:int = 8;
        public static var FNV:int = 9;
        public static var AP:int = 10;

        private var m_hashFns:Array;
        private var m_bloomFns:Array;
        private var m_results:ByteArray;
        private var m_len:int;

        public function BloomFilter(_arg1:Array, _arg2:int=45){
            var hashFns:* = _arg1;
            var len:int = _arg2;
            super();
            this.m_hashFns = new Array(RSHash, JSHash, PJWHash, ELFHash, BKDRHash, SDBMHash, DJBHash, DEKHash, BPHash, FNVHash, APHash);
            this.m_bloomFns = new Array();
            var insertFns:* = function (_arg1, _arg2:int, _arg3:Array):void{
                var _local4:int = int(_arg1);
                m_bloomFns.push(m_hashFns[_local4]);
            };
            hashFns.forEach(insertFns, this);
            this.m_results = new ByteArray();
            var i:* = 0;
            while (i < len) {
                this.m_results.writeByte(0);
                i = (i + 1);
            };
            this.m_len = len;
        }
        public static function RSHash(_arg1:String):uint{
            var _local2:uint = 378551;
            var _local3:uint = 63689;
            var _local4:uint;
            var _local5:int;
            while (_local5 < _arg1.length) {
                _local4 = ((_local4 * _local3) + uint(_arg1.charCodeAt(_local5)));
                _local3 = (_local3 * _local2);
                _local5++;
            };
            return (_local4);
        }
        public static function JSHash(_arg1:String):uint{
            var _local2:uint = 1315423911;
            var _local3:int;
            while (_local3 < _arg1.length) {
                _local2 = (_local2 ^ (((_local2 << 5) + uint(_arg1.charCodeAt(_local3))) + ((_local2 >> 2) & 1073741823)));
                _local3++;
            };
            return (_local2);
        }
        public static function PJWHash(_arg1:String):uint{
            var _local2:uint = uint((4 * 8));
            var _local3:uint = uint(((_local2 * 3) / 4));
            var _local4:uint = uint((_local2 / 8));
            var _local5:uint = (uint(4294967295) << uint((_local2 - _local4)));
            var _local6:uint;
            var _local7:uint;
            var _local8:uint;
            var _local9:uint;
            var _local10:uint;
            var _local11:int;
            while (_local11 < _arg1.length) {
                _local6 = (uint((_local6 << _local4)) + uint(_arg1.charCodeAt(_local11)));
                _local7 = uint((_local6 & _local5));
                if (_local7 != 0){
                    _local8 = ((_local7 >> _local3) & 0xFF);
                    _local9 = ~(_local5);
                    _local10 = (_local6 ^ _local8);
                    _local6 = (_local10 & _local9);
                };
                _local11++;
            };
            return (_local6);
        }
        public static function ELFHash(_arg1:String):uint{
            var _local2:uint;
            var _local3:uint;
            var _local4:int;
            while (_local4 < _arg1.length) {
                _local2 = (uint((_local2 << 4)) + uint(_arg1.charCodeAt(_local4)));
                _local3 = (_local2 & 4026531840);
                if (_local3 != 0){
                    _local2 = (_local2 ^ ((_local3 >> 24) & 0xFF));
                };
                _local2 = (_local2 & ~(_local3));
                _local4++;
            };
            return (_local2);
        }
        public static function BKDRHash(_arg1:String):uint{
            var _local2:uint = 131;
            var _local3:uint;
            var _local4:int;
            while (_local4 < _arg1.length) {
                _local3 = (uint((_local3 * _local2)) + uint(_arg1.charCodeAt(_local4)));
                _local4++;
            };
            return (_local3);
        }
        public static function SDBMHash(_arg1:String):uint{
            var _local2:uint;
            var _local3:int;
            while (_local3 < _arg1.length) {
                _local2 = (((uint(_arg1.charCodeAt(_local3)) + (_local2 << 6)) + (_local2 << 16)) - _local2);
                _local3++;
            };
            return (_local2);
        }
        public static function DJBHash(_arg1:String):uint{
            var _local2:uint = 5381;
            var _local3:int;
            while (_local3 < _arg1.length) {
                _local2 = (((_local2 << 5) + _local2) + uint(_arg1.charCodeAt(_local3)));
                _local3++;
            };
            return (_local2);
        }
        public static function DEKHash(_arg1:String):uint{
            var _local2:uint = _arg1.length;
            var _local3:int;
            while (_local3 < _arg1.length) {
                _local2 = (((_local2 << 5) ^ ((_local2 >> 27) & 31)) ^ uint(_arg1.charCodeAt(_local3)));
                _local3++;
            };
            return (_local2);
        }
        public static function BPHash(_arg1:String):uint{
            var _local2:uint;
            var _local3:int;
            while (_local3 < _arg1.length) {
                _local2 = ((_local2 << 7) ^ uint(_arg1.charCodeAt(_local3)));
                _local3++;
            };
            return (_local2);
        }
        public static function FNVHash(_arg1:String):uint{
            var _local2:uint = 2166136261;
            var _local3:uint;
            var _local4:int;
            while (_local4 < _arg1.length) {
                _local3 = (_local3 * _local2);
                _local3 = (_local3 ^ uint(_arg1.charCodeAt(_local4)));
                _local4++;
            };
            return (_local3);
        }
        public static function APHash(_arg1:String):uint{
            var _local3:uint;
            var _local2:uint = 2863311530;
            var _local4:int;
            while (_local4 < _arg1.length) {
                _local3 = uint(_arg1.charCodeAt(_local4));
                if ((_local4 & 1) == 0){
                    _local2 = (_local2 ^ ((_local2 << 7) ^ (_local3 * ((_local2 >> 3) & 536870911))));
                } else {
                    _local2 = (_local2 ^ ~((((_local2 << 11) + _local3) ^ ((_local2 >> 5) & 134217727))));
                };
                _local4++;
            };
            return (_local2);
        }

        public function BloomAdd(_arg1:String):void{
            var str:* = _arg1;
            var setBit:* = function (_arg1, _arg2:int, _arg3:Array):void{
                var _local4:int = m_results[_arg2];
                var _local5:Function = _arg1;
                var _local6:int = (_local5(str) % (m_len * 8));
                var _local7:int = (_local6 / 8);
                var _local8:int = (_local6 % 8);
                m_results[_local7] = (m_results[_local7] | (1 << _local8));
            };
            this.m_bloomFns.forEach(setBit, this);
        }
        public function BloomClear():void{
            var _local1:int;
            while (_local1 < this.m_len) {
                this.m_results[_local1] = 0;
                _local1++;
            };
        }
        public function BloomCheck(_arg1:String):Boolean{
            var str:* = _arg1;
            var getBit:* = function (_arg1, _arg2:int, _arg3:Array):Boolean{
                var _local4:Function = _arg1;
                var _local5:int = (_local4(str) % (m_len * 8));
                var _local6:int = m_results[int((_local5 / 8))];
                if ((_local6 & (1 << (_local5 % 8))) > 0){
                    return (true);
                };
                return (false);
            };
            return (this.m_bloomFns.every(getBit, this));
        }
        public function checkString():String{
            var _local1 = "";
            _local1 = this.m_results[0].toString();
            var _local2 = 1;
            while (_local2 < this.m_len) {
                _local1 = (_local1 + ("," + this.m_results[_local2]));
                _local2++;
            };
            return (_local1);
        }
        public function toString():String{
            var _local1:String = Base64.encodeByteArray(this.m_results);
            return (_local1);
        }

    }
}//package zasp.Util 
